package com.heima.Config;

import com.heima.common.exception.RabbitMQcode;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static com.heima.common.exception.RabbitMQcode.*;

@Configuration
public class MQConfig {
    //    声明路由消息交换机
    @Bean
    public DirectExchange WmdirectExchange()
    {
        return new DirectExchange(WmExchangeName);
    }

    //    声明消息存储队列
    @Bean
    public Queue SensitiveQueue()
    {
        return new Queue(WmSensitiveQueueName);
    }

    @Bean
    public Queue ChannelQueue(){
        return new Queue(WmChannelQueueName);
    }

    //    绑定交换机和队列
    @Bean
    public Binding WmSensitivebinding(Queue SensitiveQueue, DirectExchange WmdirectExchange)
    {
        return BindingBuilder.bind(SensitiveQueue).to(WmdirectExchange).with(WmSensitiveKey);
    }

    @Bean
    public Binding WmChannelbinding(Queue ChannelQueue,DirectExchange WmdirectExchange)
    {
        return BindingBuilder.bind(ChannelQueue).to(WmdirectExchange).with(WmChannelKey);
    }

}
